
require "uri"
require_relative 'google_client'

class Portfolios
	
	GOOGLE_FINANCE_API = URI.parse('http://finance.google.com/finance/feeds/default/portfolios')
	
	FINANCE_SERVICE = 'finance'

	def initialize(email, password)
		@client = Google::Client.new
		
		if !password
			file_name = './password.txt'
			file = File.new(file_name, 'r') if File.exist? file_name
			password = file.readline
			file.close
		end
		#Login
		@client.login(email, password, FINANCE_SERVICE)
	end

	def create
		creating_portfolios
	end

	def retrieve
		@client.get(URI.parse("http://finance.google.com/finance/feeds/default/portfolios"))
	end


	
	private
	def creating_portfolios
<<XML
<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gf='http://schemas.google.com/finance/2007'>
  <title>A New Portfolio</title>
  <gf:portfolioData currencyCode='USD'/>
</entry>
XML
	end
end

gp = Portfolios.new 'healer.kx.yu@gmail.com', nil
gp.retrieve
